package com.m3958.firstgwt.client.datasource;
import com.google.inject.Inject;
import com.google.inject.Singleton;
import com.m3958.firstgwt.client.constants.VoteFieldConstants;
import com.m3958.firstgwt.client.types.VoteField;
import com.m3958.firstgwt.shared.type.CommonField;
import com.m3958.firstgwt.shared.type.SmartConstants;
import com.m3958.firstgwt.shared.type.SmartParameterName;
import com.smartgwt.client.data.fields.DataSourceBooleanField;
import com.smartgwt.client.data.fields.DataSourceDateTimeField;
import com.smartgwt.client.data.fields.DataSourceIntegerField;
import com.smartgwt.client.data.fields.DataSourceTextField;

@Singleton
public class VoteDataSource extends BaseDataSource{

    public static String className = "com.m3958.firstgwt.server.model.Vote";
    
    @Inject
    public VoteDataSource(DsErrorHandler deh,VoteFieldConstants constants) {
    	setID("voteDS");
    	
    	setTitleField(CommonField.NAME.getValue());
    	
        DataSourceIntegerField parentField = new DataSourceIntegerField(SmartParameterName.PARENTID,SmartParameterName.PARENTID);

        parentField.setForeignKey(id + "." + CommonField.ID.getValue());
        parentField.setRequired(true);
        parentField.setRootValue(SmartConstants.NONE_EXIST_MODEL_ID);
        
        DataSourceTextField nameField = new DataSourceTextField(CommonField.NAME.getValue(),constants.name());
        DataSourceTextField chartTypeField = new DataSourceTextField(VoteField.CHART_TYPE.getValue(),constants.chartType());
        DataSourceDateTimeField startField = new DataSourceDateTimeField(VoteField.START_DATE.getValue(),constants.startDate());
        DataSourceDateTimeField endField = new DataSourceDateTimeField(VoteField.END_DATE.getValue(),constants.endDate());        
        
        DataSourceIntegerField minSelectField = new DataSourceIntegerField(VoteField.MIN_SELECT.getValue(),constants.minSelect());
        
        DataSourceIntegerField maxSelectField = new DataSourceIntegerField(VoteField.MAX_SELECT.getValue(),constants.maxSelect());
        
        DataSourceBooleanField hiddenField = new DataSourceBooleanField(CommonField.HIDDEN.getValue(),constants.hidden());
        
         
        addHandleErrorHandler(deh);
        
        setFields(parentField,getSiteIdField(constants),hiddenField,getIdField(),getVersionField(),nameField,getCreatedAtField(false,constants),getPositionField(constants),startField,endField,getTplNameField(),chartTypeField,minSelectField,maxSelectField);
        setClientOnly(false);
       
    }

	@Override
	protected String getModelClassName() {
		return className;
	}
}
